package utils;

public class Bitwise {

	public static long nOnes(long i) {
		i = i - ((i >> 1) & 0x55555555);
		i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
		return (((i + (i >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
	}

	public static String toString0(long n, int base) {
		String out = "";
		do
			out = n % base + out;
		while ((n /= base) > 0);
		return out;
	}

	public static String toString1(long n, int base) {
		if (n == 1)
			return "";
		String out = "";
		do {
			out = n % base + out;
		} while ((n /= base) != 1);
		return out;
	}
	
	public static String toString1R(long n, int base) {
		if (n == 1)
			return "";
		String out = "";
		do {
			out += n % base;
		} while ((n /= base) != 1);
		return out;
	}

	public static String toString(long n, int base, int len) {
		String out = "";
		for (int i = 0; i < len; i++, n /= base)
			out = n % base + out;
		return out;
	}

}
